package com.zhang.controller;

import com.zhang.dao.DepartmentDao;
import com.zhang.dao.EmployeeDao;
import com.zhang.pojo.Department;
import com.zhang.pojo.Employee;
import com.zhang.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Collection;

/**
 * @author ZhangJunqi
 * @Date 2022/2/21 -20:53
 */
//@RestController//没有web
@Controller
public class LoginController {
    @GetMapping(value = "/login")
    public String loginSubmit(User user, Model model, HttpSession session){
        System.out.println(user.toString ());
        if(!StringUtils.isEmpty (user) &&user.getUserPassword ().equals ("123")){
            session.setAttribute ("loginUser",user.getUserCode ());
            return "redirect:/main";//设置跳转，否则会出现/login?userCode=stu201701014&userPassword=1
        }else{
            model.addAttribute ("msg","账号或密码错误");
            return "index";
        }
    }

    @GetMapping(value = "/signOut")
    public String signOut(HttpSession session){
        System.out.println("退出登录 session"+session.getAttribute ("loginUser"));
        session.invalidate ();
        return "redirect:/index.html";
    }

    @GetMapping(value = "toDashboard")
    public String toDashboard(Model model){
        return "dashboard";
    }
}

